package com.ynny.Dao.Imp;

import com.ynny.Dao.CourseManageDao;
import com.ynny.Entity.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CourseImp  implements CourseManageDao {
    @Autowired
  private   JdbcTemplate  jdbcTemplate;

    @Override
    public int updateCourse(String coursesName ){
        String sql="update courses set math -1 where id =?";
        return jdbcTemplate.update(sql,coursesName);
    }
    @Override
    public List<Course> queryAllCourses(){
        String sql="select * from courses";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<Course>(Course.class));
    }
    @Override
    public Course queryCourseByName(String coursesName) {
        String sql = "select * from courses where coursesName = ?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Course.class), coursesName);
    }
}
